# -*- coding: utf-8 -*-
from BatchImpl import *
from igetui.igt_target import *
from igetui.template.igt_notification_template import *
from igt_push import *

APPKEY = ""
APPID = ""
MASTERSECRET = ""
CID1 = ""
CID2 = ""
HOST = 'http://sdk.open.api.igexin.com/apiex.htm'

def pushMessageToSingleBatch():
    push = IGeTui(HOST, APPKEY, MASTERSECRET)
    batch = BatchImpl(APPKEY, push)

    # 消息模版：
    # 1.TransmissionTemplate:透传功能模板
    # 2.LinkTemplate:通知打开链接功能模板
    # 3.NotificationTemplate：通知透传功能模板
    # 4.NotyPopLoadTemplate：通知弹框下载功能模板

    templateNoti = NotificationTemplateDemo()
    templateLink = LinkTemplateDemo()
    # template = TransmissionTemplateDemo()
    # template = NotyPopLoadTemplateDemo()

    messageNoti = IGtSingleMessage()
    messageNoti.isOffline = True
    messageNoti.offlineExpireTime = 1000 * 3600 * 12
    messageNoti.data = templateNoti

    targetNoti = Target()
    targetNoti.appId = APPID
    targetNoti.clientId = CID1

    batch.add(messageNoti, targetNoti)

    messageLink = IGtSingleMessage()
    messageLink.isOffline = True
    messageLink.offlineExpireTime = 1000 * 3600 * 12
    messageLink.data = templateLink

    targetLink = Target()
    targetLink.appId = APPID
    targetLink.clientId = CID2

    batch.add(messageLink, targetLink)
    try:
        ret = batch.submit()
        print ret
    except Exception, e:
        ret = batch.retry()
        print ret


# 通知透传模板动作内容
def NotificationTemplateDemo():
    template = NotificationTemplate()
    template.appId = APPID
    template.appKey = APPKEY
    template.transmissionType = 1
    template.transmissionContent = u"请填入透传内容"
    template.title = u"请填入通知标题"
    template.text = u"请填入通知内容"
    template.logo = "icon.png"
    template.logoURL = ""
    template.isRing = True
    template.isVibrate = True
    template.isClearable = True
    # begin = "2015-03-04 17:40:22";
    # end = "2015-03-04 17:47:24";
    # template.setDuration(begin, end)
    return template

# 通知链接模板动作内容
def LinkTemplateDemo():
    template = LinkTemplate()
    template.appId = APPID
    template.appKey = APPKEY
    template.title = u"请填入通知标题"
    template.text = u"请填入通知内容"
    template.logo = ""
    template.url = "http://www.baidu.com"
    template.transmissionType = 1
    template.transmissionContent = ''
    template.isRing = True
    template.isVibrate = True
    template.isClearable = True
    return template
